package org.hbbTlias2025.controller;

import lombok.extern.slf4j.Slf4j;
import org.hbbTlias2025.pojo.Emp;
import org.hbbTlias2025.pojo.Result;
import org.hbbTlias2025.pojo.LoginInfo;
import org.hbbTlias2025.service.EmpService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RequestMapping("/login")
@RestController
public class LoginController {

    @Autowired
    private EmpService empService;



    @PostMapping
    private Result login(@RequestBody Emp emp) {
        try {
            log.info("username:{},password:{}", emp.getUsername(), emp.getPassword());
            LoginInfo info = empService.login(emp);
            if(info != null){
                return Result.success(info);
            }
            return Result.error("登录失败，玩不起就别玩————输错了吧");
        } catch (Exception e) {
            return Result.error("登录失败，玩不起就别玩————" + e.getMessage());
        }
    }

}
